package com.vesper.mysdk;


import android.util.Log;

import androidx.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public abstract class RTCSDK {
    public static final String TAG = "MSDK";

    /**
     * 定一个常见的Reason注解，用于限制参数只能取@IntDef中声明的参数的其中一个
     */
    @IntDef({REASON_NORMAL, REASON_NOT_INIT, REASON_NOT_LOGIN, REASON_ALREADY_LOGIN, MREASON_ACCOUNT_OR_PASSWORD_WRONG})
    @Retention(RetentionPolicy.SOURCE)//指定这个注解只在源代码中保留，不会在编译后的字节码中出现
    public @interface MReason {
    }

    /**
     * 初始化SDK
     *
     * @param secretKey secretKet
     * @param appKey    appKey
     * @param callback  sdk状态的回调
     */

    //正常原因
    public static final int REASON_NORMAL = 0;
    //没有初始化
    public static final int REASON_NOT_INIT = 1;
    //没有登录
    public static final int REASON_NOT_LOGIN = 2;
    //重复登录
    public static final int REASON_ALREADY_LOGIN = 3;
    //账号密码错误
    public static final int MREASON_ACCOUNT_OR_PASSWORD_WRONG = 4;


    /**
     * 登录的状态
     */

    @IntDef({STATUS_NOT_INIT, STATUS_INITED, STATUS_LOGINED, STATUS_NOT_LOGIN})
    @Retention(RetentionPolicy.SOURCE)
    public @interface SDKStatus {
    }

    //未初始化
    public static final int STATUS_NOT_INIT = 0;

    //已初始化
    public static final int STATUS_INITED = 1;

    //未登录
    public static final int STATUS_NOT_LOGIN = 2;

    //已登录
    public static final int STATUS_LOGINED = 3;

    public static RTCSDK mSdk = null;

    public static RTCSDK initSDK(String secretKey, String appKey, MCallback callback) {
        if (mSdk != null && mSdk.getLoginStatus() != STATUS_NOT_INIT) {
            Log.e(TAG, "initSDK: SDK already initiated!");
            return mSdk;
        }else{
            mSdk = new RTCSDKImpl( secretKey,  appKey,  callback);
            return mSdk;
        }
    }

    public static void destory(){
        if (mSdk != null) {
            mSdk.destroySDK();
            mSdk = null;
        }
    }

    /**
     * 获取当前的状态
     * 使用@MStatus标记getLoginStatus返回的值，声明该方法返回的是一个状态码
     */
    @SDKStatus
    public abstract int getLoginStatus();

    public abstract void login(String uid,String password);
    public abstract void logout();
    public abstract void destroySDK();


}

